class Solution {
public:
    bool backspaceCompare(string s, string t) {
        return changestr(s) == changestr(t);
    }

    string changestr(string& s) {
        string ret;
        for (char ch : s) {
            if (ch != '#') ret += ch;
            else {
                if (ret.size()) ret.pop_back();
            }
        }
        return ret;

    }
};